﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Runtime.Remoting;
using System.Threading;
using System.Windows.Forms;

namespace BattleshipGameClient
{
    class Game : MarshalByRefObject, IGame
    {
        private IGame opponent;
        private bool opponentReadyToStart;
        private Game[] viewers;
        private Fleet myFleet;
        private Fleet opponentsFleet;
        private String myName;

        private GameForm gameForm;

        public Game(String name)
        {

            this.myName = name;
            Thread fre = new Thread(new ThreadStart(start_game_form));
            fre.IsBackground = true;
            fre.Start();

        }

        private void start_game_form()
        {
            //gameForm = new GameForm();
            Application.Run(gameForm);
        }

        public void setOpponent(IGame opponent)
        {
            this.opponent = opponent;
        }

        public String getName()
        {
            return myName;
        }

        public void readyToStart()
        {
            opponentReadyToStart = true;
        }


        public void fleetReport(Fleet fleet)
        {
            throw new NotImplementedException();
        }

        public void shoot(Point coord)
        {
            opponent.hitReport(coord, "miss");

            foreach(Game viewer in viewers)
                viewer.hitReport(coord,"miss");

            //if(myFleet.isSunk() || opponentsFleet.IsSunk)
              //  displayWinner();
        }

        public void hitReport(Point coord, string hitBoatType)
        {
            throw new NotImplementedException();
        }

        public void registerViewer(Game viewer)
        {
            throw new NotImplementedException();
        }

        public void firstShooterReport(string username)
        {
            throw new NotImplementedException();
        }

        public Game decideFirstShooter(Game player1, Game player2)
        {
            Random random = new Random();
            if (random.Next(0, 2) == 0)
                return player1;
            else
                return player2;
        }

        public void displayWinner()
        {
            throw new NotImplementedException();
        }
    }
}
